// pages/myquestions/myquestions.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
     titles:[
       "出大事了，赶快进来看一眼...",
       "是时候表演真正的技术了",
       "没有人比你更懂我了",
       "你跟我两个谈这些，你嗯是",
       "出大事了，赶快进来看一眼...",
     ],
     resultDiscreption: [
       "警察叔叔，我要报警，我交到假朋友了！",
       "够了，我们的友谊小船已经翻了",
       "难道你就是传说中的表面朋友",
       "看来我们之间还有许多事情要交流交流",
       "咱两这默契度，真是酒肉朋友的交情啊！",
       "你保住了革命友谊的火种",
       "不错，没白交你这个朋友",
       "看来我们之间还有许多事情要交流交流",
       "我的军大衣！",
       "深知我心",
       "原来最懂我的人就在这里。",
     ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    if (options.question_id){
      that.setData({
        question_id: options.question_id
      })
    }
    wx.getSystemInfo({
      success: function (res) {
        that.setData({
          winWidth: res.windowWidth,
          winHeight: res.windowHeight,
          userInfo: wx.getStorageSync('userInfo')
        })
      }
    })
    getQuestionInfo(that)
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    var that=this
    var _num = Math.floor(Math.random() * 5);
    console.log(_num)
    var _title = that.data.titles[_num];
    console.log(wx.getStorageSync("userCurrentPutQuestionId"));
    console.log(wx.getStorageSync("userid"));
    return {
      title: _title,
      path: '/pages/doQuestion/doQuestion?id=' + that.data.question_id +'&questionuserid='+wx.getStorageSync("userid"),
    }
  },
  toDraw: function () {
    wx.navigateTo({
      url: '../../pages/withdraw/withdraw',
    })
  },
  seeAnswer:function(){
    wx.navigateTo({
      url: '../../pages/answers/answers?user_id=' + wx.getStorageSync('userid') + "&question_id=" + this.data.question_id,
    })
  },
  useCurrentQuestion:function(){
    
  }
})

function getQuestionInfo(that){
  wx.request({
    url: app.globalData.allUrl + "/api/get_quest_info.php",
    data: {
      user_id: wx.getStorageSync('userid'),
      question_id: that.data.question_id
    },
    header: { 'content-type': "application/x-www-form-urlencoded" },
    method: 'POST',
    success: function (res) {
      console.log(res.data)
      for (var i = 0; i < res.data.userinfo.length; i++) {
        res.data.userinfo[i].correct_rate2 = res.data.userinfo[i].correct_rate;
        res.data.userinfo[i].correct_rate = (parseFloat(res.data.userinfo[i].correct_rate) / parseFloat(res.data.all_number) * 100).toFixed(2);
        console.log(res.data.userinfo[i].correct_rate)
      }
      that.setData({
        allPlayer: res.data.userinfo,
        all_money: res.data.data.all_money,
        allPakegeNum: res.data.data.num,
        lastPakegeNum: res.data.data.package_num,
      })
    }, fail: function () {
    }
  })
}